package com.philips.work.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.philips.common.log.annotation.Log;
import com.philips.common.log.enums.BusinessType;
import com.philips.common.security.annotation.RequiresPermissions;
import com.philips.work.domain.YwFlowTotal;
import com.philips.work.service.IYwFlowTotalService;
import com.philips.common.core.web.controller.BaseController;
import com.philips.common.core.web.domain.AjaxResult;
import com.philips.common.core.utils.poi.ExcelUtil;
import com.philips.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 总流水合计Controller
 * 
 * @author philips
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/flowTotal")
public class YwFlowTotalController extends BaseController
{
    @Autowired
    private IYwFlowTotalService ywFlowTotalService;

    /**
     * 查询总流水合计列表
     */
    @RequiresPermissions("work:flowTotal:list")
    @GetMapping("/list")
    public TableDataInfo list(YwFlowTotal ywFlowTotal)
    {
        startPage();
        List<YwFlowTotal> list = ywFlowTotalService.selectYwFlowTotalList(ywFlowTotal);
        return getDataTable(list);
    }

    /**
     * 导出总流水合计列表
     */
    @RequiresPermissions("work:flowTotal:export")
    @Log(title = "总流水合计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YwFlowTotal ywFlowTotal)
    {
        List<YwFlowTotal> list = ywFlowTotalService.selectYwFlowTotalList(ywFlowTotal);
        ExcelUtil<YwFlowTotal> util = new ExcelUtil<YwFlowTotal>(YwFlowTotal.class);
        util.exportExcel(response, list, "总流水合计数据");
    }

    /**
     * 获取总流水合计详细信息
     */
    @RequiresPermissions("work:flowTotal:query")
    @GetMapping(value = "/{ids}")
    public AjaxResult getInfo(@PathVariable("ids") String ids)
    {
        return success(ywFlowTotalService.selectYwFlowTotalByIds(ids));
    }

    /**
     * 新增总流水合计
     */
    @RequiresPermissions("work:flowTotal:add")
    @Log(title = "总流水合计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YwFlowTotal ywFlowTotal)
    {
        return toAjax(ywFlowTotalService.insertYwFlowTotal(ywFlowTotal));
    }

    /**
     * 修改总流水合计
     */
    @RequiresPermissions("work:flowTotal:edit")
    @Log(title = "总流水合计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YwFlowTotal ywFlowTotal)
    {
        return toAjax(ywFlowTotalService.updateYwFlowTotal(ywFlowTotal));
    }

    /**
     * 删除总流水合计
     */
    @RequiresPermissions("work:flowTotal:remove")
    @Log(title = "总流水合计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{idss}")
    public AjaxResult remove(@PathVariable String[] idss)
    {
        return toAjax(ywFlowTotalService.deleteYwFlowTotalByIdss(idss));
    }

    /**
     * 导入总流水合计列表
     */
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YwFlowTotal> util = new ExcelUtil<YwFlowTotal>(YwFlowTotal.class);
        List<YwFlowTotal> flowTotalList = util.importExcel(file.getInputStream());
        String message = ywFlowTotalService.importFlowTotal(flowTotalList, updateSupport);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<YwFlowTotal> util = new ExcelUtil<YwFlowTotal>(YwFlowTotal.class);
        util.importTemplateExcel(response, "流水合计数据");
    }
}
